<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\RcUser;
use App\Jobs\WxMessage;
use App\Models\Prize;
use Carbon\Carbon;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;

class RcUserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new RcUser(), function (Grid $grid) {
            $grid->column('id')->sortable();
//            $grid->column('parent_id');
            $grid->column('name');
            $grid->column('open_id');
            $grid->column('head_img')->image('',50,50);
            $grid->column('luck_sum','抽奖次数');
//           $grid->disableFilterButton();
            $grid->setActionClass(Grid\Displayers\Actions::class);
            $grid->disableEditButton();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            //禁用创建按钮
            $grid->disableCreateButton();

            $grid->export();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('insert_time','用户状态');
                $filter->day('created_at','时间');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new RcUser(), function (Show $show) {
            $show->field('id');
            $show->field('parent_id');
            $show->field('name');
            $show->field('open_id');
            $show->field('head_img');
            $show->field('integral');
            $show->field('sp_integral');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new RcUser(), function (Form $form) {
            $form->display('id');
            $form->text('parent_id');
            $form->text('name');
            $form->text('open_id');
            $form->text('head_img');
            $form->text('integral');
            $form->text('sp_integral');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
 public function selectUser(Request $request)
 {
     $time = $request->get('time');
     $end_time = Carbon::parse($time)->endOfDay()->toDateTimeString();
     $start_time = Carbon::parse($time)->toDateTimeString();
     $user = \App\Models\RcUser::query()->where(['insert_time'=>1])
         ->whereDate('created_at','>=',$start_time)
         ->whereDate('created_at','<=',$end_time)
         ->count();
     echo '查询时间新增：'.$user;
 }
}
